<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Hash;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class CommunityController extends Controller
{
   /*
        显示社区首页
   */
    public function getIndex()
    {
        // echo  333;die;
        //获取三级分类
        $menu = HomeListController::menu(0);
        //查询所有分区
        $partition = DB::table('partition')
                    ->join('user','partition.user_id','=','user.id')
                    ->select('partition.*','user.username')
                    ->get();

        //查询分区下面的板块
        foreach($partition as $k=>$v){
            $partition[$k]->sub = DB::table('plate')->where('partition_id',$v->id)->get();
        }
       
        //解析模板
        return view('home.community.index',['menu'=>$menu,'partition'=>$partition]);
    }
    public function getList($id)
    {
        // dd($id);
        //显示分页
        $menu = HomeListController::menu(0);
        $tiezi = DB::table('tiezi')
        ->join('user','tiezi.uid','=','user.id')
        ->select('tiezi.*','user.username')
        ->where('plate_id',$id)
        ->paginate(5);
        // dd($tiezi);
        return view('home.community.list',['tiezi'=>$tiezi,'id'=>$id,'menu'=>$menu]);
    }
}  
 